from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, log_loss
class CustomLogisticRegression:
    def __init__(self, C=1.0):
        self.model = LogisticRegression(C=C, penalty='l2', solver='lbfgs', max_iter=1000)

    def fit(self, X, y):
        self.model.fit(X, y)

    def predict(self, X):
        return self.model.predict(X)

    def predict_proba(self, X):
        return self.model.predict_proba(X)

    def evaluate(self, X, y, verbose=0):
        predictions = self.predict(X)
        accuracy = accuracy_score(y, predictions)
        if verbose:
            print(f"Logistic Regression 测试准确率: {accuracy:.4f}")
        return accuracy
